package com.bird.system.adapter.menu.database

import com.bird.component.database.model.richEntity
import com.bird.system.adapter.menu.database.dataobj.MenuDO
import com.bird.system.domain.menu.MenuEntity
import com.bird.system.domain.menu.vo.MenuType

/**
 * 菜单实体转数据库对象
 */
fun MenuEntity.toMenuDO(): MenuDO {
    return MenuDO(
        menuName = this.menuName,
        parentId = this.parentId,
        treePath = this.treePath,
        routeName = this.routeName,
        routePath = this.routePath,
        component = this.component,
        keepAlive = this.keepAlive,
        hidden = this.hidden,
        alwaysShow = this.alwaysShow,
        redirect = this.redirect,
        sort = this.sort,
        menuType = this.menuType.value,
        perm = this.perm,
        icon = this.icon
    ).also { it.richBase(this) }
}
/**
 * 数据库对象转菜单实体
 */
fun MenuDO.toEntity(): MenuEntity {
    return MenuEntity(
        menuName = this.menuName,
        parentId = this.parentId,
        treePath = this.treePath,
        routeName = this.routeName,
        routePath = this.routePath,
        component = this.component,
        keepAlive = this.keepAlive,
        hidden = this.hidden,
        alwaysShow = this.alwaysShow,
        redirect = this.redirect,
        sort = this.sort,
        menuType = MenuType.from(this.menuType),
        perm = this.perm,
        icon = this.icon
    ).also { it.richEntity(this) }
}